﻿Imports FinanceiroBLL
Imports FinanceiroDAL
Public Class EditaParcelamentoFRM
#Region "Variáveis"
    Dim objp As New ItensCtasPagarBLL
    Public codctp, qtditem As Integer
    Dim objBLL As New ContasPagarBLL
    Dim tabitens As New DataTable
    Dim tab As DataTable
    Dim aux, ccc, contas, stat, vardgv2 As Integer
    Public Op As Char
    Dim somaGridpagar As Integer = 0 'alterar
    Dim valpago, desc, juros As Decimal
    Dim total As Decimal = 0
    Dim calc As Decimal = 0
    Dim soma As Decimal = 0
    Dim somadgvdados As Decimal = 0
    Dim totalgrid As Decimal = 0
    Dim valorparcela As Decimal = 0
    Dim datcompra As Date
    Dim forn As String
#End Region
#Region "LOAD"
    Private Sub EditaParcelamentoFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If (Op = "U") Then
            limpar()
            objconexao.carregaCombo(CBFormaPgto, "Generico.Gen_FormaPagamento", "pag_codigo", "pag_descricao", "sta_codigo < 2", "pag_descricao")
            carregagrid()
            ' TXTCodigo.Text = codctp
            Lista()
        Else : Op = "P"
            limpar()
            carregagrid()
            '    TXTCodigo.Text = codctp
            Lista()
            objconexao.carregaCombo(CBFormaPgto, "Generico.Gen_FormaPagamento", "pag_codigo", "pag_descricao", "sta_codigo < 2", "pag_descricao")
        End If

    End Sub
#End Region
    Sub carregagrid()
        '     Dim cod As Integer = Val(TXTCodigo.Text)
        Dim parc As Decimal = 0
        Decimal.TryParse(TXTVlrparcela.Text.Replace("R$", ""), parc)
        Try
            DGVCtasPagar.DataSource = objp.localizar(codctp, 2)
            DGVCtasPagar.Refresh()
            somaGridpagar = DGVCtasPagar.RowCount.ToString 'soma a linha de registros
            TXTSoma.Text = objp.Somactp(codctp).ToString()
            total = TXTSoma.Text.Replace("R$", "")
            TXTSoma.Text = FormatCurrency(TXTSoma.Text.Replace("R$", "").Replace(" ", ""))
        Catch
        End Try
    End Sub
#Region "Limpar"
    Sub limpar()
        CBFormaPgto.SelectedValue = -1
        TXTBoletotitulo.Text = ""
        '    TXTCodigo.Text = ""
        TXTParcela.Text = ""
        '     TXTSoma.Text = ""
        TXTVlrparcela.Text = ""
    End Sub
#End Region
#Region "Lista"
    Sub Lista() '*1
        Try
            tabitens = Nothing
            tabitens = New DataTable
            tabitens.Columns.Add("icp_codigo", GetType(Integer))
            tabitens.Columns.Add("ctp_codigo", GetType(Integer))
            tabitens.Columns.Add("icp_datapagamento", GetType(String))
            tabitens.Columns.Add("icp_valor", GetType(Decimal))
            tabitens.Columns.Add("pag_codigo", GetType(Integer))
            tabitens.Columns.Add("icp_datavencimento", GetType(Date))
            tabitens.Columns.Add("icp_valorpago", GetType(Decimal))
            tabitens.Columns.Add("icp_desconto", GetType(Decimal))
            tabitens.Columns.Add("icp_jam", GetType(Decimal))
            tabitens.Columns.Add("icp_parcela", GetType(Integer))
            tabitens.Columns.Add("con_codigo", GetType(Integer))
            tabitens.Columns.Add("icp_boletocheque", GetType(String))
            tabitens.Columns.Add("sta_codigo", GetType(Integer))
            DGVDados.DataSource = tabitens
        Catch
            Throw New Exception("Erro ao gerar lista")
        End Try
    End Sub
#Region "Carrega na Datagirdview"
    Sub Carrega_Selecao(item As ItensCtasPagarBLL)
        Try
            Dim soma As Decimal
            Dim linha As DataRow
            linha = tabitens.NewRow
            linha("icp_codigo") = item.icpcodigo
            linha("ctp_codigo") = item.ctpcodigo
            linha("icp_datapagamento") = item.icp_datapagamento
            linha("icp_valor") = item.icp_valor
            linha("pag_codigo") = item.pag_codigo
            linha("icp_datavencimento") = item.icp_datavencimento
            linha("icp_valorpago") = item.icp_valorpago
            linha("icp_desconto") = item.icp_desconto
            linha("icp_jam") = item.icp_jam
            linha("icp_parcela") = item.icp_parcela
            linha("con_codigo") = item.con_codigo
            linha("icp_boletocheque") = item.icp_boletocheque
            tabitens.Rows.Add(linha)
            tabitens.AcceptChanges()
            For Each x In tabitens.Rows
                soma += Decimal.Parse(x("icp_valor"))
            Next
            TXTTotalGrid.Text = soma
            Me.LBNumRegistros.Text = DGVDados.RowCount.ToString 'soma a linha de registros
        Catch ex As Exception
            Throw New Exception("Erro ao inserir na grid")
        End Try
    End Sub
#End Region

#End Region
#Region "Carrega Campos"
    Sub CarregaCampos()
        Try
            Dim Objp As New ItensCtasPagarBLL()
            Objp = New ItensCtasPagarBLL(codctp, 2)
            LCodigo.Text = objp.icpcodigo
            aux = objp.ctpcodigo
            '   TXTDtpagto.Text = objp.icp_datapagamento
            TXTVlrparcela.Text = objp.icp_valor
            CBFormaPgto.SelectedValue = objp.pag_codigo
            If (Not IsNothing(objp.icp_datavencimento)) Then DTPDtVencimento.Text = objp.icp_datavencimento
            valpago = objp.icp_valorpago
            desc = objp.icp_desconto
            juros = objp.icp_jam
            TXTParcela.Text = objp.icp_parcela
            contas = objp.con_codigo
            TXTBoletotitulo.Text = objp.icp_boletocheque
            stat = objp.sta_codigo
        Catch ex As Exception
            MsgBox(ex)
        End Try
    End Sub
#End Region
#Region "Valida Item e Valor"
    Function validaItem() As Boolean
        Dim ret As Boolean
        ret = False
        For Each linha As DataRow In tabitens.Rows
            If (linha("icp_codigo") = Val(LCodigo.Text)) Then
                ret = True
            End If
        Next
        Return ret
    End Function
#End Region
#Region "Adicionar"
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)
        Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)
        Decimal.TryParse(TXTSoma.Text.Replace("R$", ""), soma)
        Try
            If (TXTVlrparcela.Text <> "" Or TXTVlrparcela.Text <> "") Then
                If (stat = 4) Then
                    If Math.Round((totalgrid)) < (Math.Round(soma)) Then
                        Dim objit As New ItensCtasPagarBLL()
                        objit.icpcodigo = Val(LCodigo.Text)
                        objit.ctpcodigo = aux
                        objit.icp_valor = TXTVlrparcela.Text
                        objit.pag_codigo = CBFormaPgto.SelectedValue
                        objit.icp_datavencimento = DTPDtVencimento.Text
                        objit.icp_valorpago = valpago 'campo total + jam -desc
                        objit.icp_desconto = desc
                        objit.icp_jam = juros
                        objit.icp_parcela = TXTParcela.Text 'num de parcela
                        objit.con_codigo = contas
                        objit.icp_boletocheque = TXTBoletotitulo.Text
                        objit.sta_codigo = stat
                        Carrega_Selecao(objit)
                        limpar()
                    Else
                        MsgBox("Os valores não conferem com o lançamento!", MsgBoxStyle.Question)
                    End If
                Else
                    MsgBox("Parcela fechada, não pode ser alterado!", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox("Preencha os campos obrigatórios", MsgBoxStyle.Exclamation)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End Sub
#End Region
#Region "Carrega variaveis"
    Sub carregaVariaveis()
        Dim tab As DataTable

        Try
            tab = objBLL.localizacod(aux)
            ccc = tab.Rows(0)("ccc_codigo").ToString()
            datcompra = tab.Rows(0)("ctp_dtcompra").ToString()
            forn = tab.Rows(0)("ctp_fornprestador").ToString()
            TXTVlrparcela.Text = tab.Rows(0)("icp_valor").ToString()
            TXTParcela.Text = tab.Rows(0)("icp_parcela").ToString()
            CBFormaPgto.SelectedValue = tab.Rows(0)("pag_codigo").ToString()
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Salvar"
    Private Sub TSBSAlvar_Click(sender As System.Object, e As System.EventArgs) Handles TSBSAlvar.Click
        Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)
        Decimal.TryParse(TXTSoma.Text.Replace("R$", ""), soma)

        Try

            '  If somadgvdados <> 0 Then
            carregaVariaveis()
            If (MessageBox.Show("Deseja finalizar o parcelamento?", "Finalização", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes) Then
                'validar se as parcelas batem
                If (Math.Round(totalgrid) = Math.Round(soma)) Then
                    objBLL = New ContasPagarBLL(aux, ccc, 0, datcompra, "", forn)
                    Dim objp As ItensCtasPagarBLL
                    For Each linha As DataRow In tabitens.Rows
                        objp = New ItensCtasPagarBLL(Val(0), aux, Nothing, 0, CBFormaPgto.SelectedValue, Nothing, valpago, desc, juros, 0, contas, TXTBoletotitulo.Text, 4)
                        objp.icpcodigo = linha("icp_codigo")
                        objp.icp_parcela = linha("icp_parcela")
                        objp.icp_datavencimento = linha("icp_datavencimento")
                        objp.icp_valor = linha("icp_valor")
                        objBLL.lCtasPagar.Add(objp)
                    Next
                Else
                    Throw New Exception("O valor total não corresponde ao valor declarado da nota, por favor confira os itens")
                End If
            Else
                MsgBox("Campos vazios!")
            End If
            ' objp.excluir(aux)
            objBLL.Inserir()
            MessageBox.Show("Parcelamento gravado com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            objBLL.limpar()
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
#End Region
#Region "Fechar"
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Me.Close()
        objBLL = New ContasPagarBLL
        objBLL = Nothing
    End Sub
#End Region
    'Sub verifica()
    '    Try
    '        If soma < totalgrid Then 'se txtsoma(soma) = txttotalgrid(totalgrid)
    '            DGVCtasPagar.ReadOnly = False
    '            If DGVCtasPagar.ReadOnly = True Then
    '            Else
    '                MsgBox("Não é possível incluir mais itens!")
    '            End If
    '        End If
    '    Catch ex As Exception
    '    End Try
    'End Sub
    Function validaentrada() As Boolean
        Dim ret As Boolean
        ret = False
        If totalgrid < soma Then
            ret = True
        End If
        Return ret
    End Function
#Region "BTNIncluir"
    Private Sub BTNIncluir_Click(sender As System.Object, e As System.EventArgs) Handles BTNIncluir.Click
        Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)
        Decimal.TryParse(TXTSoma.Text.Replace("R$", ""), soma)
        Decimal.TryParse(TXTVlrparcela.Text.Replace("R$", ""), valorparcela)
        Try
            desabilita()
            BTNExcluir.Enabled = True
            validagrid()
            If (Not validaItem()) Then
                If (validaentrada()) Then
                    If ((TXTParcela.Text <> "0") And (TXTVlrparcela.Text <> "0")) Then

                        If somaGridpagar <> Val(LBNumRegistros.Text) Then
                            If (Math.Round(soma) <> Math.Round(totalgrid)) Then
                                If (Math.Round(totalgrid)) < Math.Round(soma) Then
                                    DGVCtasPagar.Refresh()
                                    Button1_Click("", e)
                                Else
                                    MsgBox("Valor das parcelas maior que o total! Redefinir o valor das parcelas", MsgBoxStyle.Exclamation)
                                    limpar()
                                    TXTVlrparcela.SelectAll()
                                End If
                            Else

                            End If
                        Else
                            MsgBox("Dados não podem sem mais inseridos", MsgBoxStyle.Exclamation)
                            BTNIncluir.Enabled = False
                            ' MsgBox("Número de parcelas não correspodem ao selecionado!")
                        End If
                    Else
                        MsgBox("Preencha os campos obrigatórios!", MsgBoxStyle.Exclamation)
                    End If
                Else : DGVCtasPagar.ReadOnly = True
                    MsgBox("Todas as parcelas foram editadas")
                    BTNIncluir.Enabled = False
                End If
            Else
                MessageBox.Show("Parcela já inserida!")
                BTNIncluir.Select()
                TXTParcela.Text = ""
                TXTBoletotitulo.Text = ""
                CBFormaPgto.Text = Nothing
            End If

        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region
#Region "KeyPress"
    Private Sub TXTCodigo_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
        If Not Char.IsNumber(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub
    Private Sub EditaParcelamentoFRM_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub

    Private Sub TXTBoletotitulo_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TXTBoletotitulo.KeyPress
        If Not Char.IsLetterOrDigit(e.KeyChar) And Not e.KeyChar = "-" And Not e.KeyChar = vbBack Then
            e.Handled = True
        End If
        'permite letra e numeros e bolta do back space
    End Sub
#End Region
#Region "Excluir"
    Private Sub BTNExcluir_Click(sender As System.Object, e As System.EventArgs) Handles BTNExcluir.Click
        Try
            If DGVCtasPagar.Rows.Count > 0 Then
                BTNExcluir.Enabled = True
                Dim indice As Integer
                indice = -1
                For Each linha As DataGridViewRow In DGVDados.SelectedRows
                    If (Not linha.Cells("icp_codigo") Is Nothing) Then
                        indice = linha.Index
                    End If
                Next
                If (indice <> -1) Then
                    tabitens.Rows.RemoveAt(indice)
                    tabitens.AcceptChanges()
                    limpar()
                    TXTTotalGrid.Text = "0"
                    LBNumRegistros.Text = "0"
                    TXTVlrparcela.Text = "0"
                    TXTParcela.Text = "0"
                Else : Throw New Exception("Operação Inválida! Selecione um lançamento para remover")
                End If
            Else
                BTNExcluir.Enabled = False
                MsgBox("Não há dados para exclusão")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
#End Region
#Region "TXTVlrparcela Leave"
    Private Sub TXTVlrparcela_Leave(sender As System.Object, e As System.EventArgs) Handles TXTVlrparcela.Leave
        valida()
    End Sub
#End Region
#Region "Cor de fundo do datagridview"
    Private Sub DGVDados_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs)
        If DGVDados.Rows(e.RowIndex).Index Mod (2) = 1 Then
            DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Gainsboro
        End If
    End Sub
#End Region
    Sub habilita()
        TXTBoletotitulo.Enabled = True
        TXTVlrparcela.Enabled = True
        DTPDtVencimento.Enabled = True
        BTNIncluir.Enabled = True
        CBFormaPgto.Enabled = True
    End Sub

    Sub desabilita()
        TXTBoletotitulo.Enabled = False
        TXTVlrparcela.Enabled = False
        DTPDtVencimento.Enabled = False
        BTNIncluir.Enabled = False
        CBFormaPgto.Enabled = False
    End Sub
    Sub calcula() 'ADD
        Dim totalgrid As Decimal = 0
        Dim soma As Decimal
        Dim calc As Decimal = 0
        Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)
        Decimal.TryParse(TXTSoma.Text.Replace("R$", ""), soma)
        Try
            If (totalgrid = 0) Then
                TXTVlrparcela.Text = tab.Rows(0)("icp_valor").ToString()
            End If
            If totalgrid > 0 Then
                TXTVlrparcela.Text = ""
                Dim parcelas As Integer
                parcelas = Val(LBNumRegistros.Text)
                Dim resul As Integer = 0
                resul = somaGridpagar - parcelas
                calc = (soma - totalgrid) / resul
                TXTVlrparcela.Text = calc
            End If
        Catch ex As Exception

        End Try
       
    End Sub
#Region "DataGridView CellDouble Click"
    Private Sub DGVCtasPagar_CellDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVCtasPagar.CellDoubleClick
        Try
            If DGVCtasPagar.Rows.Count > 0 Then
                CBFormaPgto.Enabled = True
                habilita()
                If (DGVCtasPagar.Rows(e.RowIndex).Cells(13).Value <> "Fechado") Then
                    vardgv2 = DGVCtasPagar.CurrentRow.Cells("DataGridViewTextBoxColumn13").Value.ToString()
                    tab = objp.localizar(vardgv2, 1)
                    LCodigo.Text = tab.Rows(0)("icp_codigo").ToString()
                    aux = tab.Rows(0)("ctp_codigo").ToString()
                    '    TXTVlrparcela.Text = tab.Rows(0)("icp_valor").ToString() 'x
                    calcula()
                    CBFormaPgto.SelectedValue = tab.Rows(0)("pag_codigo").ToString()
                    DTPDtVencimento.Text = tab.Rows(0)("icp_datavencimento").ToString() 'x
                    valpago = tab.Rows(0)("icp_valorpago").ToString()
                    desc = tab.Rows(0)("icp_desconto").ToString()
                    juros = tab.Rows(0)("icp_jam").ToString()
                    TXTParcela.Text = tab.Rows(0)("icp_parcela").ToString() 'x
                    contas = tab.Rows(0)("con_codigo").ToString()
                    TXTBoletotitulo.Text = tab.Rows(0)("icp_boletocheque").ToString() 'x
                    stat = tab.Rows(0)("sta_codigo").ToString()
                Else
                    MsgBox("Lançamento já fechado!", MsgBoxStyle.Exclamation)
                End If
            Else
                MsgBox("Selecione uma linha")
            End If

        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region
#Region "valida"
    Sub valida()
        Dim parcela As Decimal = 0
        Dim valortotal As Decimal = 0
        Dim totalgrid As Decimal = 0
        Try
            If (Decimal.TryParse(TXTVlrparcela.Text.Replace("R$", ""), parcela)) Then
            Else : parcela = "0,00"
            End If
            If (Decimal.TryParse(TXTSoma.Text.Replace("R$", ""), valortotal)) Then
            Else : valortotal = "0,00"
            End If
            If (Decimal.TryParse(TXTTotalGrid.Text.Replace("R$", ""), totalgrid)) Then
            Else : totalgrid = "0,00"
            End If
            If (DTPDtVencimento.Value < Date.Now.ToShortDateString) Then
                MsgBox("Data de vencimento menor que a data de hoje!.Redefinir a data.", MsgBoxStyle.Exclamation)
                DTPDtVencimento.Select()
            End If
            If (parcela > valortotal) Then
                MsgBox("Valor maior que a soma das parcelas!", MsgBoxStyle.Critical)
                TXTVlrparcela.Text = "0,00"
                TXTVlrparcela.SelectAll()
            End If
            If TXTVlrparcela.Text <> "" Then
                TXTVlrparcela.Text = FormatCurrency(TXTVlrparcela.Text)
            Else
                TXTVlrparcela.Text = "0,00"
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "TXTVlrparcela Propriedades"

    Private Sub TXTVlrparcela_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TXTVlrparcela.KeyPress
        If Not Char.IsNumber(e.KeyChar) And Not e.KeyChar = vbBack And Not e.KeyChar = "." And Not e.KeyChar = "," Then
            e.Handled = True
        End If
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            valida()
        End If
    End Sub
#End Region
#Region "TXTTotalGRid"
    Private Sub TXTTotalGrid_TextChanged(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.TextChanged
        If (TXTTotalGrid.SelectionStart) Then
            TXTTotalGrid.SelectAll()
        End If
    End Sub

    Private Sub TXTTotalGrid_Leave(sender As System.Object, e As System.EventArgs) Handles TXTTotalGrid.Leave
        valida()
    End Sub
#End Region
#Region "DTPDtVencimento"
    Private Sub DTPDtVencimento_Leave(sender As System.Object, e As System.EventArgs) Handles DTPDtVencimento.Leave
        valida()
    End Sub
#End Region
#Region "DGV Pre Paint"
    Private Sub DGVCtasPagar_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DGVCtasPagar.RowPrePaint
        '    Me.DGVCtasPagar.CurrentRow.Selected = False
        Try
            If DGVCtasPagar.Rows.Count > 0 Then
                If (DGVCtasPagar.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVCtasPagar.Rows(e.RowIndex).Cells(11).Value = Date.Now.ToShortDateString) Then
                    DGVCtasPagar.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Yellow 'hoje
                End If
                If (DGVCtasPagar.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVCtasPagar.Rows(e.RowIndex).Cells(11).Value > Date.Now.ToShortDateString) Then
                    DGVCtasPagar.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'não vencidas (futuro)
                End If
                If (DGVCtasPagar.Rows(e.RowIndex).Cells(13).Value = "Aberto") And (DGVCtasPagar.Rows(e.RowIndex).Cells(11).Value < Date.Now.ToShortDateString) Then
                    DGVCtasPagar.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Salmon 'vencidos
                End If
                If (DGVCtasPagar.Rows(e.RowIndex).Cells(13).Value = "Fechado") And (DGVCtasPagar.Rows(e.RowIndex).Cells(12).Value <> Nothing) Then
                    DGVCtasPagar.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.PaleGreen 'fechados e pagos
                End If
                'Else
                '    DGVCtasPagar.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White 'futuros
            End If
        Catch
        End Try
    End Sub
#End Region
#Region "Soma Grid"
    Sub validagrid()
        Dim valor As Decimal = 0
        Dim indice As Integer = -1
        Try
            For Each col As DataGridViewRow In DGVDados.Rows
                valor = valor + col.Cells(3).Value
            Next
            somadgvdados = valor + valorparcela
            '   linhas = DGVDados.RowCount
            If (somadgvdados > soma) Then
                MsgBox("Valores não correspondem, redefina as parcelas", MsgBoxStyle.Critical)
            End If
        Catch ex As Exception
        End Try
    End Sub

#End Region
    Private Sub DGVDados_CellContentDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVDados.CellContentDoubleClick
        BTNExcluir.Enabled = True
    End Sub
End Class